//
//  HWNewfeatureViewController.m
//
//

#import "ZYNewfeatureViewController.h"
#import "FirstViewController.h"
#import "SCDBTool.h"

const NSInteger   kImageCount      = 1;

@interface ZYNewfeatureViewController () <UIScrollViewDelegate>

@end

@implementation ZYNewfeatureViewController
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setupScrollView];
    //初始化数据库
//    [SCDBTool ZYDbInit];
    
    [ZYUserDefaults setObject:@"31.51035" forKey:CBYlatitude];
    [ZYUserDefaults setObject:@"114.3957" forKey:CBYlongitude];
    [ZYUserDefaults synchronize];
   

    [SCUserTool logOut];
}



- (void)setupScrollView
{
    UIScrollView *scrollView = [[UIScrollView alloc] init];
    scrollView.frame = self.view.bounds;
    scrollView.delegate = self;
    [self.view addSubview:scrollView];
    
    // 2.添加图片
    CGFloat imageW = kWidth;
    CGFloat imageH = KHeight;
    for (int index = 0; index<kImageCount; index++) {
        UIImageView *imageView = [[UIImageView alloc] init];
        if(isIphone6){
            NSString *name =  [NSString stringWithFormat:@"welcome_%d-667h@2x.png", index];;
            imageView.image = [UIImage imageNamed:name];
        }else{
            NSString *name =  [NSString stringWithFormat:@"welcome_%d", index];;
            imageView.image = [UIImage imageNamed:name];
        }
        CGFloat imageX = index * imageW;
        imageView.frame = CGRectMake(imageX, 0, imageW, imageH);
        [scrollView addSubview:imageView];
 
        if (index == kImageCount-1) {
            [self setupLastImageView:imageView];
        }else{
            [self setupJumpBtn:imageView];
        }
    }
    
    scrollView.contentSize = CGSizeMake(imageW * kImageCount, 0);
    scrollView.showsHorizontalScrollIndicator = NO;
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
}

- (void)setupJumpBtn:(UIImageView *)imageView
{
    imageView.userInteractionEnabled = YES;
    UIButton *jumpBtn = [[UIButton alloc]init];
//    [jumpBtn setImage:[UIImage imageNamed:@"welcome_jump"] forState:UIControlStateNormal];
    [imageView addSubview:jumpBtn];
    [jumpBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(imageView).mas_equalTo(20);
//        make.right.equalTo(imageView).mas_equalTo(-20);
//        make.size.mas_equalTo(CGSizeMake(80, 44));
        make.bottom.left.right.equalTo(imageView);
        make.height.mas_equalTo(imageView.mas_height).multipliedBy(0.2);
    }];
    [jumpBtn addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchDown];

}


- (void)setupLastImageView:(UIImageView *)imageView
{

    imageView.userInteractionEnabled = YES;
    UIButton *startButton = [[UIButton alloc]init];
    [startButton setBackgroundColor:[UIColor clearColor]];
    [imageView addSubview:startButton];
    [startButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.equalTo(imageView);
        make.height.equalTo(imageView.mas_height).multipliedBy(0.2);
    }];
    [startButton addTarget:self action:@selector(start) forControlEvents:UIControlEventTouchDown];
    
}


- (void)start
{
    JTNavigationController *nav = [[JTNavigationController alloc]initWithRootViewController:[[FirstViewController alloc]init]];
    self.view.window.rootViewController = nav;
}


@end
